<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>销售雷达</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">


    <link rel="stylesheet" href="assets/css/amazeui.min.css?v=2.9">
    <link rel="stylesheet" href="assets/css/style.css?v=2.3">
    <link rel="stylesheet" href="assets/css/index.css?v=2.3">
    <link rel="stylesheet" href="assets/css/extend.css?v=2.3">
    <link rel="stylesheet" href="assets/css/icons.css?v=2.3">
    <link rel="stylesheet" href="assets/css/iscroll.css">
    <!--<script src="./assets/js/vue2.2.2.min.js"></script>-->
    <script src="assets/js/vue.js"></script>

    <script src="assets/js/iscroll.js"></script>
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/amazeui.min.js"></script>
    <script src="assets/common.js"></script>
    <script src="assets/js/md5.js"></script>
    <link rel="stylesheet" href="assets/js/layui/css/layui.css">
    <script type='text/javascript' src='assets/js/layui/layui.js'></script>
    <style>
        #wrapper{
            padding-bottom: 50px;
        }
    </style>
</head>
<body class="bg-gray">
    <div id='amz-main'>
    <div id="wrapper" v-cloak>
        <div class="scroller">
            <section  data-tag="css-nav" v-for="datainfo in datainfos">
                <div v-if="show(datainfo.create_time)">
                    <!--{{timestamp = datainfo.create_time}}-->
                    <div class="am-text-center am-padding-top-ss"><span class="am-he-time">{{timestampToTime(datainfo.create_time)}}</span></div>
                </div>
                <div class="am-g am-benj" v-on:click="userDetail(datainfo.user_id)">
                    <div class="bg-white font-14 am-padding-left-sm am-padding-top-sm am-padding-bottom-sm padding-right-2rems prelative am-listborder">
                        <div class="box ">
                            <div class="width-45px"><img v-bind:src="datainfo.head_icon"
                                                         class="am-img-responsive border-circle"></div>
                            <div class="box-1">
                                <div class="font-16 font-color-2 am-listcent">{{datainfo.name}}<span class="am-color-blue">{{datainfo.description}}</span>
                                    <div v-if="datainfo.action_code == '1001'">{{datainfo.num}}次</div>
                                </div>
                            </div>
                        </div>

                        <!--<i class="icon-arrow-right-3"></i>-->
                    </div>
                </div>

            </section>
        </div>
    </div>
    <footer data-am-widget="navbar" class="am-navbar am-cf am-navbar-default ">
        <ul class="am-navbar-nav am-cf am-avg-sm-4">
            <li>
                <a href="javascript:void(0)" onclick="location.reload()" class="selected">
                    <img src="assets/images/icons/radar-on.png"
                         alt="首页"/>
                    <span class="am-navbar-label">雷达</span>
                </a>
            </li>
            <li>
                <a onclick='messge()' class="">
                    <img src="assets/images/icons/news.png"
                         alt="商品"/>
                    <span class="am-navbar-label">消息</span>
                </a>
            </li>

            <li onclick='custom()'>
                <a  class="">
                    <img src="assets/images/icons/user.png"
                         alt="推广助手"/>
                    <span class="am-navbar-label">客户</span>
                </a>
            </li>
            <li onclick='my()'>
                <a  class="">
                    <img src="assets/images/icons/me.png"
                         alt="个人中心"/>
                    <span class="am-navbar-label">我的</span>
                </a>
            </li>
        </ul>
    </footer>
</div>

<script>
    var mask;
    var islast=0;
    var recount=0;//刷新次数
    var totalpage;
    layui.use('layer', function(){
        var layer = layui.layer;
    });
    var code = getQueryString("code");
    var sessionid = getQueryString("sessionid");
    var enterpriseid = getQueryString("enterpriseid");
    var page = {
        "page_num": 1,
        "page_size": 12
    }

    $(function () {

        setTimeout(function(){
            mask = layer.msg('正在加载', {icon: 16});
            //alert(history.length);
            if(history.length>1){
                pageData(sessionStorage.getItem("session"))
            }else if (sessionid == null) {
                aiUserInfo();
            }else {
                pageData(sessionid)
            }
        },200)


    })


    /**
     * 获取用户信息及权限
     */
    function aiUserInfo() {

        $.ajax({
            type: 'POST',
            url: baseUrl + 'v3.0/login/ai?code=' + code+'&enterpriseid='+enterpriseid,
            contentType: 'application/json',
            success: function (data) {
                layer.close(mask);
                //无权限 则跳转
                if (data == 0) {
                    window.location.href = "企业微信/没有权限.html";
                }
                //有权限
                else {
                    sessionid=data;
                    sessionStorage.setItem("session",sessionid);
                    pageData(data);
                }
            }
        })
    };


    var w;
    function pageData(sessionid) {
        var uuid=randomString();
        var sign = hex_md5(JSON.stringify(page)+sessionid+uuid+"-keji").toUpperCase();
        $.ajax({
            type: 'POST',
            url: baseUrl + 'v3.0/action/list',
            contentType: 'application/json',
            data: JSON.stringify(page),
            headers: {'session_id': sessionid,"uuid":uuid,"sign":sign},
            success: function (result) {
                layer.close(mask);
                totalpage=result.total_num/result.page_size;
                if (result.data_list.length!=0){
                    var timestamp = result.data_list[0].create_time;
                }else{
                    var timestamp;
                }

                //注册vue
                w = new Vue({
                    el: "#wrapper",
                    data: {
                        static: "",
                        datainfos: result.data_list
                    },
                    methods: {
                        my: function () {
                            window.location.href = "销售雷达/我的.html?sessionid=" + sessionid;
                        },
                        userDetail:function(userid){
                            window.location.href = '销售雷达/客户详情.html?sessionid='+sessionid+'&userid=' + userid;
                        },
                        custom: function () {
                            window.location.href = "销售雷达/客户.html?sessionid=" + sessionid;
                        },
                        messge: function () {

                            window.location.href = "销售雷达/消息.html?sessionid=" + sessionid;
                        },
                        show: function (create_time) {
                            if (timestamp == create_time) {
                                return true;
                            }
                            else if (timestamp - create_time > 5 * 60 * 1000) {
                                timestamp = create_time;
                                return true;
                            } else {
                                return false;
                            }
                        }
                    }
                })

            }

        })
    }
    function nextPage(){
        if (totalpage<=1){
            return;
        }
        if(islast==1){
            mask = layer.msg('最后一页了');
            setTimeout(function(){
                layer.close(mask);
            },2000)
            return;//最后一页了
        }
        mask = layer.msg('加载下一页', {icon: 16});
        ++page.page_num;
        var uuid=randomString();
        var sign = hex_md5(JSON.stringify(page)+sessionid+uuid+"-keji").toUpperCase();
        $.ajax({
            type: 'POST',
            url: baseUrl + 'v3.0/action/list',
            contentType: 'application/json',
            data: JSON.stringify(page),
            headers: {'session_id': sessionid,"uuid":uuid,"sign":sign},
            success: function (data) {
                if(data.total_num<data.page_size*data.page_num)
                {
                    islast=1;
                }
                for(var i in data.data_list)
                {
                    w.datainfos.push(data.data_list[i]);
                    layer.close(mask);
                }

            }
        })
    }
    function reloadPage() {
        if (totalpage<=1){
            return;
        }
        recount++;
        if (recount==1){
            mask = layer.msg('页面刷新中', {icon: 16});
            page.page_num=1;
            var uuid=randomString();
            var sign = hex_md5(JSON.stringify(page)+sessionid+uuid+"-keji").toUpperCase();
            $.ajax({
                type: 'POST',
                url: baseUrl + 'v3.0/action/list',
                contentType: 'application/json',
                data: JSON.stringify(page),
                headers: {'session_id': sessionid,"uuid":uuid,"sign":sign},
                success:function(d){
                    w.datainfos=d.data_list
                    setTimeout(function () {
                        recount=0;
                        islast=0;
                    },1000)
                    layer.close(mask);

                }
            })
        }

    }
    function custom () {
        window.location.href = "销售雷达/客户.html?sessionid=" + sessionid;
    }
    function my () {
        window.location.href = "销售雷达/我的.html?sessionid=" + sessionid;
    }
    function messge () {

        window.location.href = "销售雷达/消息.html?sessionid=" + sessionid;
    }

    //滚动条在Y轴上的滚动距离
    function getScrollTop() {
        var scrollTop = 0,
            bodyScrollTop = 0,
            documentScrollTop = 0;
        if (document.body) {
            bodyScrollTop = document.body.scrollTop;
        }
        if (document.documentElement) {
            documentScrollTop = document.documentElement.scrollTop;
        }
        scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
        return scrollTop;
    }
    //文档的总高度
    function getScrollHeight() {
        var scrollHeight = 0,
            bodyScrollHeight = 0,
            documentScrollHeight = 0;
        if (document.body) {
            bodyScrollHeight = document.body.scrollHeight;
        }
        if (document.documentElement) {
            documentScrollHeight = document.documentElement.scrollHeight;
        }
        scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
        return scrollHeight;
    }
    //浏览器视口的高度
    function getWindowHeight() {
        var windowHeight = 0;
        if (document.compatMode == "CSS1Compat") {
            windowHeight = document.documentElement.clientHeight;
        } else {
            windowHeight = document.body.clientHeight;
        }
        return windowHeight;
    }
    window.onscroll = function () {
        if (getScrollTop() + getWindowHeight() == getScrollHeight()) {
            nextPage();
        }

        if (getScrollTop() == 0) {
            //

            reloadPage();
        }
    };
</script>
</body>
</html>